﻿@inject IStringLocalizer<DialogModalDialog> Localizer

<Button OnClick="@OnResultDialogClick">@Localizer["ModalDialogButton"]</Button>
<BlockLogger @ref="Trace" class="mt-3" />

@code {
    [Inject]
    [NotNull]
    private DialogService? DialogService { get; set; }

    [NotNull]
    private BlockLogger? Trace { get; set; }

    private int DemoValue1 { get; set; } = 1;

    private async Task OnResultDialogClick()
    {
        var result = await DialogService.ShowModal<ResultDialogDemo>(new ResultDialogOption()
        {
            Title = "Modal popup with return value",
            ComponentParamters = new Dictionary<string, object>
            {
                [nameof(ResultDialogDemo.Value)] = DemoValue1,
                [nameof(ResultDialogDemo.ValueChanged)] = EventCallback.Factory.Create<int>(this, v => DemoValue1 = v)
            }
        });

        Trace.Log($"The return value of the popup window is: {result} The return value of the component is: {DemoValue1}");
    }
}
